package com.llxz.blog.ucenter.controller;

import com.llxz.blog.ucenter.entity.Provice;
import com.llxz.blog.ucenter.service.UserService;
import com.llxz.blog.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by IntelliJ IDEA.
 *
 * @author zzh
 * @description:. date: 2021/9/13 9:33
 * /ucenter/register/total/count
 */

@RestController
@RequestMapping("/ucenter")
public class StaController {
    @Autowired
    UserService userService;

    @GetMapping("get/ip/adress")
    public R getIpAdress() {
        List<Provice> res = userService.getIpAdressNum();
        List<Integer> data = new ArrayList<>();
        for (Provice p : res) {
            data.add(p.getNum());
        }
        return R.ok().data("data",data);
    }


    @GetMapping("register/total/count")
    public R registerTotalCount() {
        int count = userService.countTotalRegister();
        return R.ok().data("name","用户注册总数").data("total", count);
    }

    @GetMapping("get/online/num")
    public R getOnlineNum() {
        int num = userService.countOnlineNum();
        return R.ok().data("num",num);
    }

}
